#ifndef DEVICEMONITOR_H
#define DEVICEMONITOR_H
#pragma once

#include "receive_processor.h"

#include <QWidget>
#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QStackedWidget>
#include <QPushButton>
#include <QListWidget>
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QLabel>
#include <QGridLayout>
#include <QChart>
#include <QChartView>
#include <QLineSeries>
#include <QValueAxis>
#include <QTimer>
#include <QRandomGenerator>
#include <QVector>
#include <QFile>
#include <QGroupBox>
#include <QMap>
// #include <Q>
// 设备数据结构
// struct DeviceData {
//     QVector<double> value;
//     // QVector<double> current;
//     // QVector<double> power;
// };

///设备实时监控页面
class DeviceMonitor : public QWidget
{
    Q_OBJECT
public:
    explicit DeviceMonitor(QWidget *parent = nullptr);
    void setupUI();
    // void createOverviewPage();
    void create_Param_Pages();
    void setupData();
    void setupConnections();
    void configureChart(QChart *chart);
    QLabel* createStatusLabel(const QString &title);
    QWidget* createCurrentValueBar();
    int update_construct(QList<Receive_Processor*> *receive_processors);
    QList<QList<QLabel*>* > *device_labels;//设备页的标签
    QList<QList<QLabel*>* > *device_out_of_top_labels;//设备页的超出阈值标签
    // QList<QTreeWidgetItem*>*device_items;//设备的树节点
    //设备和参数的共同的节点列表
    QList<QTreeWidgetItem*>*tree_item_list;
    QList<QLabel*> *Warning_Light_List;//警报灯图片显示
    QList<QList<bool> *> *param_out_of_setting;//检测参数超出阈值的bool列表
    QPixmap *L_green;//绿色显示灯
    QPixmap *L_red;//红色显示灯
    QPixmap *L_gray;//灰色显示灯
    QPixmap *L_yellow;//黄色显示灯
signals:

public slots:
    void updateData(QList<Receive_Processor*> *receive_processors,int index);
    // void updateChart(int deviceIndex);

private slots:
    void change_page(QTreeWidgetItem*,int);
private:
    // 界面组件
    // QListWidget *deviceList;
    QTreeWidget*device_Tree;

    QStackedWidget *stackedWidget;
    // 数据结构
    static const int deviceCount = 3;
    QList<QVector<double>* >*devices_param_data;
    QList<QLabel*> *last_update_list;//设备的最后更新时间的QLabel的列表
    // 图表相关数据
    struct ChartComponents {
        QChart *chart;
        QLineSeries *valueSeries;
        QLabel *value_label;
        QValueAxis *Axis_X;
        QValueAxis *Axis_Y;
    };
    QList<QList<ChartComponents*>*>*param_components;

    QTimer *dataTimer;
};


#endif // DEVICEMONITOR_H
